package com.tju.ffmpeg

import java.util.Scanner
fun main(args: Array<String>) {
    val read = Scanner(System.`in`)

    var n = read.nextInt()
    val heights: MutableList<Int> = mutableListOf()
    for (i in 0 until n) {
        heights.add(read.nextInt())
    }
    if (n<2) {
        println(0)
        println(1)
    }
    merge(heights)
    val result: MutableList<Int> = mutableListOf()
    while (heights.size>1) {
        minus(heights)
        merge(heights)
        result.add(heights.size)
    }
    println(result.size)
    for (i in result.indices) {
        print("${result[i]} ")
    }
}



fun minus(heights: MutableList<Int>) {
    var min = heights[0]
    heights.forEach {
        if (it!=0 && (min==0 || min>it)) min = it
    }
    for (i in heights.indices) {
        if(heights[i]!=0) {
            heights[i] -= min
        }
    }
}

fun merge(heights: MutableList<Int>) {
    var index = 1
    while (index<heights.size) {
        if (heights[index]==heights[index-1]) {
            heights.removeAt(index)
        } else {
            index++
        }
    }
}